// JavaScript Document
function killErrors() {
	return true;
}
//window.onerror = killErrors;
var Ajax_msg = "获取失败";

function trim(s) {
	return  s.replace(/(^\s*)|(\s*$)/g, "");
}

function checkbook() {
	if(trim($("#title").val()) == '' || trim($("#title").val()) == '请输入您的姓名') {
		alert('请输入您的姓名');
		$("#title").focus();
		$("#title").val("");
		return false;
	}
	if(trim($("#contact").val()) == '' || trim($("#contact").val()) == '请输入您的联系方式') {
		alert('请输入您的联系方式');
		$("#contact").focus();
		$("#contact").val("");
		return false;
	}
	if(trim($("#content").val()) == '' || trim($("#content").val()) == '请输入您的内容') {
		alert('请输入您的内容');
		$("#content").focus();
		$("#content").val("");
		return false;
	}
	/*var soap='<?xml version="1.0" encoding="utf-8"?>' +
	 '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
	 '  <soap:Body>' +
	 '    <AddBook xmlns="http://xinlisoft.com/">' +
	 '      <title>'+encodeURI(trim($("#title").val()))+'</title>' +
	 '      <contact>'+encodeURI(trim($("#contact").val()))+'</contact>' +
	 '      <content>'+encodeURI(trim($("#content").val()))+'</content>' +
	 '      <CustomValue></CustomValue>' +
	 '    </AddBook>' +
	 '  </soap:Body>' +
	 '</soap:Envelope>';
	 var url=webdir+"API/FormSubmit.asmx";*/
	$('#showmsg').html("<img src='../images/loading.gif'>");
	/*$.ajax({
	 url:url,
	 async:true,
	 beforeSend: function(xhr) {
	 xhr.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
	 xhr.setRequestHeader("SOAPAction", "http://xinlisoft.com/AddBook");
	 },
	 type: "POST",
	 dataType: "xml",
	 data: soap,
	 contentType: "text/xml; charset=\"utf-8\"",
	 error:function(XMLHttpRequest, textStatus, errorThrown){
	 $('#showmsg').html(Ajax_msg);
	 },
	 complete:function(xmlData,textStatus){
	 var result=$(xmlData.responseXML).find("AddBookResult").eq(0).text();
	 $('#showmsg').html("<img src='../images/loading.gif'>"+result.substring(1));
	 if(result.substring(0,1)==0)
	 {
	 $("#title").val("");$("#contact").val("");$("#content").val("");
	 setTimeout("window.location.href='?';","1000");
	 }
	 }
	 });*/
	var title = $("#title").val();
	var contact = $("#contact").val();
	var content = $("#content").val();
	//alert(title);
	$.post('guestbook.php', {action: 'saveadd', title: title, contact: contact, content: content}, function(data) {
		//alert(data);
		if(data == 2) {
			$('#showmsg').html("提交留言成功！");
			setTimeout("window.location.href='?';", "1000");
		} else {
			$('#showmsg').html("提交留言有误！");
			setTimeout("window.location.href='?';", "1000");
		}
	});
	return false;
}

function IndexBanner() {
	$.get("viewerData.xml", function(d) {
		var k = 0;
		$(d).find("item").each(function() {
			var $item = $(this);
			var $img = $item.attr("img");
			var $url = $item.attr("url");
			var $title = $item.attr("title");
			$(".swiper-wrapper").append("<div class='swiper-slide'><a href='" + $url + "' target='_blank'><img src='" + $img + "' width='100%' border='0' /></a></div>");
		});
		var width = window.innerWidth;
		$(".swiper-container").height(width >= 640 ? 242 : width * 242 / 640);
		var mySwiper = new Swiper('.swiper-container', {
			pagination: '.pagination',
			loop: true,
			grabCursor: true,
			paginationClickable: true,
			autoplay: 2000
		});
	});
}

function GetNextPage(BoxID, Url, classid, page, PageCount) {
	$.ajax({
		type: "get",
		cache: false,
		url: webdir + Url + "?id=" + classid + "&page=" + page + "&t=" + Math.random(),
		timeout: 20000,
		success: function(result) {
			$('#' + BoxID).append($(result).find("#" + BoxID).html());
			if(page < PageCount) {
				$(".gochannel a").unbind("click").click(function() {
					GetNextPage(BoxID, Url, classid, page + 1, PageCount);
				});
			} else {
				$(".gochannel a").unbind("click");
			}
		}
	});
}

function GoBackByFollowID(url, followid, classid) {
	if(followid > 0) {
		window.location.href = url + '?id=' + followid;
	} else {
		window.location.href = url + '?id=' + classid;
	}
}

function ToggleClassnav(BoxID) {
	$("#" + BoxID).slideToggle();
}

$(window).resize(function() {
	var width = window.innerWidth;
	$(".xtools").width(width);
	if($(".swiper-container").length > 0) {
		$(".swiper-container").height(width >= 640 ? 242 : width * 242 / 640);
	}
});